# 通过正则表达式筛选百度首页信息
import requests
from fake_useragent import FakeUserAgent
import re

# 定义请求头，发起网络请求
headers = {'User-Agent': FakeUserAgent().random}
url = 'https://www.baidu.com'
response = requests.get(url, headers=headers)

# 将文本内容赋值
main_info = response.text

# 定义筛选规则
match_rule = '"card_title":"(.*?)","ext"'

# 得到筛选规则
result = re.findall(match_rule, main_info)
print(result)



